﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookManageSystem
{
    public partial class FormUser: Form
    {
        public FormUser()
        {
            InitializeComponent();
        }

        private void 退出登录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定退出？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    == DialogResult.Yes)
                this.Close();
        //    Application.Exit();
        }

        private void FormUser_Load(object sender, EventArgs e)
        {
            this.label1.Text = $"用户：{form1.name} {form1.id}";
        }

        private void 注销账号ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //删除数据库中当前账号信息
            if (MessageBox.Show("确定注销当前账号？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
            {
                //获取到要注销的账号
                int id = form1.id ;
                Dao dao = new Dao();
                dao.Concnect();
                string sql = $"delete T_User where Uid = {id}";
                if (dao.Execute(sql) > 0)
                {
                    //注销账号成功
                    MessageBox.Show("注销账号成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dao.DaoClose();
                    this.Close();
                }
                else
                {
                    //注销失败
                    MessageBox.Show("注销账号失败", "消息", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    dao.DaoClose();
                }
            }
        }
    }
}
